#include "userhelper.h"
#include <QFile>
#include <QJsonDocument>
UserHelper::UserHelper()
{
   // QFile f("D:/user.json");
   // f.open(QFile::ReadOnly);
   // setUserinfo(QJsonDocument::fromJson(f.readAll()).toVariant().toMap());
   // f.close();
}

UserHelper *UserHelper::instance()
{
    static UserHelper global;
    return &global;
}

QVariantMap UserHelper::userinfo() const
{
    return m_userinfo;
}

void UserHelper::setUserinfo(const QVariantMap &newUserinfo)
{
    if (m_userinfo == newUserinfo)
        return;
    m_userinfo = newUserinfo;
    qDebug()<<"========userinfo========"<<newUserinfo;
    emit userinfoChanged();
}

void UserHelper::resetUserinfo()
{
    setUserinfo({}); // TODO: Adapt to use your actual default value
}

QString UserHelper::token()
{
   return m_userinfo["token"].toString();
}
